<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>YOUKU OPENAPI File Upload Demo</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="description" content="">
		<meta name="author" content="">
		<link
			href="http://open.youku.com/assets/lib/bootstrap2.1.0/css/bootstrap.css"
			rel="stylesheet">
		<link
			href="http://open.youku.com/assets/lib/bootstrap2.1.0/css/bootstrap-responsive.css"
			rel="stylesheet">
		<style>
.uploadfile {
	width: 150px;
	height: 14px;
	vertical-align: top;
}
</style>
		<script src="http://open.youku.com/assets/lib/jquery-1.8.1.min.js"></script>
		<script src="http://open.youku.com/assets/lib/uploadjs.php"></script>
		<script>
	//document.domain = "youku.com";
	var USE_STREAM_UPLOAD = true;
	jQuery(document)
			.ready( function() {
				//oauth_opentype:iframe,newWindow,currentWindow
					//iframe
					var param = {
						client_id :"85umcobwswozr4r6",
						access_token :"c52defaa741795bc7fd9a133277d0a01",
						oauth_opentype :"iframe",
						oauth_redirect_uri :"http://test.youku.com/youkuupload/oauth_result.html",
						oauth_state :"",
						completeCallback :"uploadComplete"
					};
					//newWindow
					//var param = {client_id:"85umcobwswozr4r6",access_token:"c52defaa741795bc7fd9a133277d0a01",oauth_opentype:"newWindow",oauth_redirect_uri:"http://test.youku.com/youkuupload/oauth_result_newwindow.html",oauth_state:"",completeCallback:"uploadComplete"};
					//currentWindow
					/*
						var param = {client_id:"85umcobwswozr4r6",access_token:"c52defaa741795bc7fd9a133277d0a01",oauth_opentype:"currentWindow",oauth_redirect_uri:"http://test.youku.com/youkuupload/upload.html",oauth_state:"",completeCallback:"uploadComplete"};
						var reg = new RegExp("(^|\\#|&)access_token=([^&]*)(\\s|&|$)", "i");  
						if (reg.test(location.href)){
							var access_token = unescape(RegExp.$2.replace(/\+/g, " ")); 
							param.access_token = access_token;
						}
					 */
					youkuUploadInit(param);

				});

	function uploadComplete(data) {
		alert("videoid=" + data.videoid + ";title=" + data.title);
	}
</script>
	</head>
	<body>
		<div id="youku-upload">
			<div class="container">
				<form class="well form-horizontal" name="video-upload">
					<fieldset>
						<div class="control-group">
							<label class="control-label" for="spanSWFUploadButton">
								选择文件：
							</label>
							<div id="uploadControl" class="controls">

							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="input01">
								标题：
							</label>
							<div class="controls">
								<input type="text" class="input-xlarge" id="input01"
									name="title">
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="textarea">
								简介：
							</label>
							<div class="controls">
								<textarea class="input-xlarge" id="textarea" rows="3"
									name="description"></textarea>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="input02">
								标签：
							</label>
							<div class="controls">
								<input type="text" class="input-xlarge" id="input02" name="tags">
								<span class="help-inline"></span>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label" for="category-node">
								类别：
							</label>
							<div class="controls">
								<select id="category-node" name="category"></select>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label">
								版权所有
							</label>
							<div class="controls">
								<label class="radio inline">
									<input type="radio" name="copyright_type" id="copyright_type2"
										value="original" checked="">
									原创
								</label>
								<label class="radio inline">
									<input type="radio" name="copyright_type" id="copyright_type1"
										value="reproduced">
									转载
								</label>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label">
								视频权限
							</label>
							<div class="controls">
								<label class="radio inline">
									<input type="radio" name="public_type" id="public_type1"
										value="all" checked="">
									公开
								</label>
								<label class="radio inline">
									<input type="radio" name="public_type" id="public_type2"
										value="friend">
									仅好友
								</label>
								<label class="radio inline">
									<input type="radio" name="public_type" id="public_type3"
										value="password">
									输入密码观看
								</label>
								<label class="radio inline" style="display: none" id="passwrod">
									<input type="text" class="input " name="watch_password">
								</label>
							</div>
						</div>
						<div class="form-actions">
							<button type="submit" class="btn btn-primary start"
								id="btn-upload-start">
								<i class="icon-upload icon-white"></i>
								<span>开始上传</span>
							</button>
						</div>
					</fieldset>
				</form>
				<div class="row">
					<div class="span5" id="upload-status-wraper"></div>
				</div>
				<br>
				<div class="well">
					<h3>
						说明
					</h3>
					<ul>
						<li>
							最大支持上传
							<strong>1 GB</strong> 视频文件
						</li>
						<li>
							允许上传的视频格式为：wmv,avi,dat,asf,rm,rmvb,ram,mpg,mpeg,3gp,mov,mp4,m4v,dvix,dv,dat,
							</br>
							mkv,flv,vob,ram,qt,divx,cpk,fli,flc,mod。不符合格式的视频将会被丢弃，请确保视频格式的正确性，避免上传失败
						</li>
						<li>
							<strong>本程序仅支持高版本的chrome或firefox浏览器</strong>
						</li>
					</ul>
				</div>
			</div>
			<div id="complete"></div>
			<div id="login"
				style="width: 100%; height: 100%; position: fixed; z-index: 999; left: 0px; top: 0px; overflow: hidden; display: none;">
			</div>

			<script>
	//document.domain = "youku.com";
	var USE_STREAM_UPLOAD = true;
	jQuery(document)
			.ready( function() {
				//Oauth授权的三种页面跳转方式iframe,newWindow,currentWindow
					//iframe跳转方式
					var param = {
						client_id :"85umcobwswozr4r6",
						access_token :"c52defaa741795bc7fd9a133277d0a01",
						oauth_opentype :"iframe",
						oauth_redirect_uri :"http://test.youku.com/youkuupload/oauth_result.html",
						oauth_state :"",
						completeCallback :"uploadComplete",
						categoryCallback :"categoryLoaded"
					};
					//newWindow新弹出窗口方式
					//var param = {client_id:"85umcobwswozr4r6",access_token:"c52defaa741795bc7fd9a133277d0a01",oauth_opentype:"newWindow",oauth_redirect_uri:"http://test.youku.com/youkuupload/oauth_result_newwindow.html",oauth_state:"",completeCallback:"uploadComplete",categoryCallback:"categoryLoaded"};
					//currentWindow当前窗口方式
					/*
					    var param = {client_id:"85umcobwswozr4r6",access_token:"c52defaa741795bc7fd9a133277d0a01",oauth_opentype:"currentWindow",oauth_redirect_uri:"http://test.youku.com/youkuupload/upload.html",oauth_state:"",completeCallback:"uploadComplete",categoryCallback:"categoryLoaded"};
					    var reg = new RegExp("(^|\\#|&)access_token=([^&]*)(\\s|&|$)", "i");  
					    if (reg.test(location.href)){
					        var access_token = unescape(RegExp.$2.replace(/\+/g, " ")); 
					        param.access_token = access_token;
					    }
					 */
					youkuUploadInit(param);

				});
	//上传完成时回调方法
	function uploadComplete(data) {
		alert("videoid=" + data.videoid + ";title=" + data.title);
	}

	//分类加载后回调方法
	function categoryLoaded(data) {
		if (data.categories) {
			var tpl = '';
			for ( var i = 0; i < data.categories.length; i++) {
				if (data.categories[i].term == 'Ads') {
					tpl += '<option value="' + data.categories[i].term
							+ '" selected>' + data.categories[i].label
							+ '</option>';
				} else {
					tpl += '<option value="' + data.categories[i].term + '" >'
							+ data.categories[i].label + '</option>';
				}
			}
			$("#category-node").html(tpl);
		}
	}
</script>
	</body>
</html>
